package control;

import java.awt.FileDialog;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

import model.Cell;
import model.Sheet;
import model.XLBufferedReader;

import view.Gui;
import view.StatusArea;
import xl.Address;

class OpenMenuItem extends FileMenuItem {
    public OpenMenuItem(Gui gui, StatusArea statusArea) {
        super(gui, statusArea, "Open");
        action = FileDialog.LOAD;
    }

    public void action(String name) {
        try {
            XLBufferedReader reader = new XLBufferedReader(name);
            HashMap<Address, Cell> loadMap = new HashMap<Address, Cell>();
            reader.load(loadMap);
            Sheet test = new Sheet(loadMap);
            try {
            	test.lookForErrors();
            	gui.replaceSheet(loadMap);
            } catch (Exception e) { 
            	statusArea.setText(e.getMessage());
            }
        } catch (Exception e) {
            statusArea.setText(e.getMessage());
        }
    }
}